﻿using Contract.Business.Entity;
using Contract.Business.Filter;
using Contract.Business.Process;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Fast.Odonto.Presentation.Web.Controllers
{
    public class ConsultaController : Controller
    {
        BPConsulta _process;
        BPConsulta Processo
        {
            get
            {
                if (_process == null)
                    _process = new BPConsulta();

                return _process;
            }
        }
        public ActionResult Index()
        {
            List<BEConsulta> lista = Processo.ObterTodos(new FEConsulta());
            return View(lista);
        }

        public ActionResult ConsultaPersonalizada()
        {
            FEConsulta filtro = new FEConsulta();

            short diaDaSemana = (short)DateTime.Today.DayOfWeek;
            filtro.DataInicio = DateTime.Today.AddDays(-diaDaSemana);
            filtro.DataFim = DateTime.Today.AddDays(13 - diaDaSemana);
            
            List<BEConsulta> lista = Processo.ObterTodos(filtro);
            return View(lista);
        }

        public ActionResult Details(int id)
        {
            return View();
        }

        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(BEConsulta consulta)
        {
            try
            {
                Processo.Salvar(consulta);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        public ActionResult Edit(int id)
        {
            return View();
        }

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        public ActionResult Delete(int id)
        {
            return View();
        }

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
